﻿using UnityEngine;
using System.Collections;
/// <summary>
/// 声音管理类 by vincent
/// 
/// </summary>
public class SoundManager
{
    /// <summary>
    /// 初始按钮声音量
    /// </summary>
    public float initSound;
    /// <summary>
    /// 初始背景音乐音量
    /// </summary>
    public float initVolumn;
    public string BGMName;
    private string preBGMName;
    private AudioSource src;
    public SoundManager(float sound, float volumn, string BGMName)
    {
        this.initSound = sound;
        this.initVolumn = volumn;
        this.BGMName = BGMName;
        src = GameManager.Instance.GetComponent<AudioSource>();
    }
    /// <summary>
    /// 播放其他BGM,loop的话循环播放名为name的BGM，不是Loop的话只播放一次名为name的BGM，接着播放原来的BGM。
    /// </summary>
    public void playBGM(string name,bool isLoop)
    {
        if (name.Equals(""))
        {
            return;
        }
        preBGMName = BGMName;
        BGMName = name;
        src.loop = isLoop;
        AudioClip clip = Resources.Load("Client/Music/" + name) as AudioClip;
        if (isLoop)
        {
            src.clip = clip;
            src.Play();
        }
        else
        {
        }
        
    }
    public void playPreBGM()
    {
        if (preBGMName==null)
        {
            return;
        }
        AudioClip clip = Resources.Load("Client/Music/" + preBGMName) as AudioClip;
        src.clip = clip;
        src.Play();
        string tmp = BGMName;
        BGMName = preBGMName;
        preBGMName = tmp;
    }

}
